import {STORAGE_KEY} from '../../api/config'
Component({
    /**
   * 组件的属性列表
   */
  properties: {
    selected: { 
      type: Number,
      value: 0
    },
  },
  /**
   * 页面的初始数据
   */
  data: {
    color: "#000000",
    roleId: wx.getStorageSync(STORAGE_KEY.ROLE_ID), // 从缓存中获取用户角色ID
    selectedColor: "#1396DB",
    list:[{}],
    allList: [
      {
        list1: [
          { "text": "首页", "pagePath": "/pages/main/main", 
              "iconPath": "/images/menu/ic_menu_choice_nor.png",
               "selectedIconPath": "/images/menu/ic_menu_choice_pressed.png" },
          { "text": "我的", "pagePath":   "/pages/self/self",
           "iconPath": "/images/menu/ic_menu_me_nor.png", 
           "selectedIconPath": "/images/menu/ic_menu_me_pressed.png"}
        ],
        list2: [ 
          { "text": "首页", "pagePath": "/pages/main/main", 
          "iconPath": "/images/menu/ic_menu_choice_nor.png",
           "selectedIconPath": "/images/menu/ic_menu_choice_pressed.png" },
          { "text": "我的", "pagePath":   "/pages/self/self",
          "iconPath": "/images/menu/ic_menu_me_nor.png", 
          "selectedIconPath": "/images/menu/ic_menu_me_pressed.png"}
        ]
      }
    ]
  },
  lifetimes:{
    attached:function (){
      console.log("重新获取角色对应导航栏" + this.data.roleId)

       // 根据用户角色设置导航项列表
       if (this.data.roleId == 0) {
        this.setData({
          list: this.data.allList[0].list1
        });
      } else if (this.data.roleId == 1) {
        this.setData({
          list: this.data.allList[0].list2
        });
      }
      wx.setStorageSync('tabBarlist', this.data.list); // 将导航项列表存入缓存
    },
  },

  methods:{
    switchTab(e:any) {
      console.log("切换导航页",e)
      // 切换导航项
      const data = e.currentTarget.dataset;
      const path = data.path;

      wx.switchTab({
        url: path
      });
    }
  }
})